package procilege.impl.formatter;

import java.util.Collection;
import java.util.Iterator;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.lang.BoolExprAnd;
import procilege.lang.BoolExprElement;

@PlaceTypeMetadata(type = BoolExprAnd.class)
public class BoolExprAndFormatter implements PlaceType<ExprFormatTraveller> {

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();

		Collection<BoolExprElement> terms = ((BoolExprAnd) place).getTerms();

		Iterator<BoolExprElement> itr = terms.iterator();
		if (itr.hasNext()) {

			BoolExprElement t = itr.next();
			tr.setout(t);

			while (itr.hasNext()) {

				t = itr.next();

				sb.append("&&");
				tr.setout(t);
			}
		}
	}
}